package com.example.myapplication2

import android.content.Context
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import kotlinx.android.synthetic.main.activity_register.*

class RegisterActivity : AppCompatActivity(), View.OnClickListener {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_register)
//        button4.setOnClickListener{
//            val inputText = editText.text.toString()
//            Log.d("RegisterActivity", "onClick: 1")
//            Toast.makeText(this, inputText, Toast.LENGTH_LONG).show()
//        }
        button4.setOnClickListener(this)
        button5.setOnClickListener(this)
        supportActionBar?.hide()//隐藏自带标题栏
    }
    companion object {
        fun actionStart(context: Context, data1: String, data2: String) {
            val intent = Intent(context, SecondActivity::class.java)
            intent.putExtra("param1", data1)
            intent.putExtra("param2", data2)
            context.startActivity(intent)
            //Log.d("RegisterActivity", data1+data2)
        }
    }

    override fun onClick(v: View?) {
        when (v?.id) {
            R.id.button4 -> {
                val inputText = editText.text.toString()
                Log.d("RegisterActivity", "onClick: 1")
                Toast.makeText(this, inputText, Toast.LENGTH_LONG).show()
//                if (progressBar.visibility == View.VISIBLE) {
//                    progressBar.visibility = View.GONE
//                } else {
//                    progressBar.visibility = View.VISIBLE
//                }
                progressBar.progress = progressBar.progress + 10

            }
            R.id.button5 ->{
                 Log.d("RegisterActivity", "onClick: 1")
                 AlertDialog.Builder(this).apply {
                     setTitle("This is Dialog")
                     setMessage("Something important.")
                     setCancelable(false)
                     setPositiveButton("OK") { dialog, which ->
                     }
                     setNegativeButton("Cancel") { dialog, which ->
                     }
                     show()
                 }
             }

        }
    }
}